package com.zgt.dao.impl;

import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.zgt.dao.SettingDao;
import com.zgt.model.Setting;

@Repository("settingDao")
public class SettingDaoImpl implements SettingDao {
	private HibernateTemplate hibernateTemplate;

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public void saveSetting(Setting setting) {
		hibernateTemplate.saveOrUpdate(setting);
	}

	public Setting listSetting(int id) {
		Setting setting = new Setting();
//		setting.setId(id);
		List<Setting> settings=hibernateTemplate.findByCriteria(DetachedCriteria.forClass(Setting.class).add(Restrictions.eq("id", id)));
		Iterator<Setting> isettings = settings.iterator();
		while (isettings.hasNext()) {
			setting = isettings.next();
		}
//		System.out.println(setting.getSysname());
		return setting;
	}

}
